﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TPAMain数据维护工具V2
{
    public partial class frmLogViewer : Form
    {
        SqlTools sqt;

        string strDefualtSelectString = "select 修改时间,修改内容 from ModifyLog";

        public frmLogViewer()
        {
            InitializeComponent();
        }

        private void frmLogViewer_Load(object sender, EventArgs e)
        {
            sqt = new SqlTools(GeneralTools.GetConnectionString(Properties.Settings.Default.Host, Properties.Settings.Default.DBName));
        }

        private void chkDate_CheckedChanged(object sender, EventArgs e)
        {
            dtpFrom.Enabled = chkDate.Checked;
            dtpTo.Enabled = chkDate.Checked;
        }

        private void chkContent_CheckedChanged(object sender, EventArgs e)
        {
            txtContent.Enabled = chkContent.Checked;
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            string strTmpSelectString = strDefualtSelectString;
            if (chkDate.Checked)
            {
                if (strTmpSelectString.Contains(" where "))
                {
                    strTmpSelectString += " and ";
                }
                else
                {
                    strTmpSelectString += " where ";
                }
                strTmpSelectString += "修改时间 between '" + dtpFrom.Value.ToString("yyyy-MM-dd") + "' and '" + dtpTo.Value.ToString("yyyy-MM-dd") + "'";
            }
            if (chkContent.Checked)
            {
                if (strTmpSelectString.Contains(" where "))
                {
                    strTmpSelectString += " and ";
                }
                else
                {
                    strTmpSelectString += " where ";
                }
                strTmpSelectString += "修改内容 like '" + txtContent.Text + "'";
            }
            strTmpSelectString +=" order by 修改时间";
            dgv1.DataSource = sqt.GetData(strTmpSelectString);
            dgv1.AutoResizeColumns();
            tsslResult.Text = "共" + dgv1.Rows.Count.ToString() + "条记录。";
        }
    }
}
